// JavaScript Document

function formValidator(){
	// Make quick references to our fields
	//var regno = document.getElementById('txtRegno');
	var ini = document.getElementById('txtIni');
	var first = document.getElementById('txtFn');
	var last = document.getElementById('txtLn');
	var gender = document.getElementById('sltGen1');
	var gender = document.getElementById('sltGen2');
	//var gender = document.getElementById('sltGen');
	//var byear = document.getElementById('sltYr');
	//var bmonth = document.getElementById('sltMon');
	var nic = document.getElementById('txtNic');
	var bdate= document.getElementById('txtBd');
	var address = document.getElementById('txtAdd');
	var contact = document.getElementById('txtCn');
	var email = document.getElementById('txtEmail');
	
	
	// Check each input in the order that it appears in the form!
	//if(notEmpty(regno, "Registration Number cannot be empty")){
	  //if(isNumeric(regno, "Registration Number should be numeric ")){
		
			if(notEmpty(first, "First Name cannot be empty")){
				
					if(notEmpty(last, "Last Name cannot be empty")){
				       
						    if(madeRadioSelection()){
							   //if(madeSelection(byear, "Select the Birth Year")){
								  //if(madeSelection(bmonth, "Select the Birth Month")){ 
								      if(madeSelection(bdate, "Select the Birth Date")){
										  if(emptyLengthrestrict(nic, 10, 10,"Nic no length should be 10")){
											  if(notEmpty(address, "Address cannot be empty")){
												 if(emptyNumeric(contact, "Contact Number should be numeric ")){
													 if(emptyEmail(email, "Please enter a valid email address")){
											              
								                                
								                                   
		                                                              loadXMLDoc();
                                                                             //return true;
																                          
																                        
					                                                                  
					                                                               }
				                                                                 }
				                                                             }
				                                                          }
				                                                      }
				                                                  }
				                                           //    }
		                                                 // }
	                                                  //}
	                                              //}
	                                      }
	                               }
		                        
		                
		             
	return false;
   }
   
   
   
   
   
   
   
   function loadXMLDoc()
{


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText;
	//window.open("../admin/student_search.php",'_blank');
    }
  }
    
    var regno = document.getElementById('txtRegno').value;
	
	var ini = document.getElementById('txtIni').value;
	
	var first = document.getElementById('txtFn').value;
	var last = document.getElementById('txtLn').value;
	if(document.getElementById("sltGen1").checked) {
	var gender = document.getElementById('sltGen1').value ;
	}
	else
	{
    var gender = document.getElementById('sltGen2').value;
	}
	
	//var gender = document.getElementById('sltGen').value;
	//var byear = document.getElementById('sltYr').value;
	//var bmonth = document.getElementById('sltMon').value;
	var nic = document.getElementById('txtNic').value;
	var bdate= document.getElementById('txtBd').value;
	var address = document.getElementById('txtAdd').value;
	var contact = document.getElementById('txtCn').value;
	var email = document.getElementById('txtEmail').value;
	var jdtx = document.getElementById('jdt').value;
	
	
	var queryString ="?first=" + first +"&last="+last+ "&ini=" + ini +"&gender="+gender+"&bdate="+bdate+ "&address=" + address +"&contact="+contact+ "&email=" + email +"&nic="+nic+"&regno="+regno+"&jdt="+jdtx;
	
xmlhttp.open("GET","../logic/update/student_update.php"+queryString ,true);
xmlhttp.send();
}

 function mailload()
{
	var emailX = document.getElementById('txtEmail');
	var emails = document.getElementById('txtEmail').value;
       if(!emails==""){
		   if (emailValidator(emailX, "not a valid email")){
			   
			   if (window.XMLHttpRequest)
                            {// code for IE7+, Firefox, Chrome, Opera, Safari
                               xmlhttp=new XMLHttpRequest();
                            }
                           else
                              {// code for IE6, IE5
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                                }
                              xmlhttp.onreadystatechange=function()
                               {
                              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                 {
									//document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText; 
									 
                                var x=xmlhttp.responseText;
								if(x=="true"){
									document.getElementById("ajaxDiv1").innerHTML="Existing Email Address ";
									document.getElementById('txtEmail').value="";
								}else{
									document.getElementById("ajaxDiv1").innerHTML=""; 
									
									}
									}
                                }
								var x=document.getElementById('txtRegno').value;
                               var y=document.getElementById('txtEmail').value;
                               var queryString ="?email=" + y+"&reg="+x;
                               xmlhttp.open("GET","../logic/load/student_mail_up.php"+queryString,true);
                                xmlhttp.send();	  

			   
			         }
		      }

}



	/*function clearx()
{
	
	 document.getElementById("myForm").reset(); 
     document.getElementById("ajaxDiv").innerHTML="";
}
	*/
	function nicload(){
		
		var nicx = document.getElementById('txtNic');
	    var nic = document.getElementById('txtNic').value;
	
		
		
		if(!(nic=="")){
		
		if(lengthRestriction(nicx, 10, 10,"Nic No length should be 10"))
								{
									
								if (window.XMLHttpRequest)
                            {// code for IE7+, Firefox, Chrome, Opera, Safari
                               xmlhttp=new XMLHttpRequest();
                            }
                           else
                              {// code for IE6, IE5
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                                }
                              xmlhttp.onreadystatechange=function()
                               {
                              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                 {
									//document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText; 
									 
                                var w=xmlhttp.responseText;
								if(w=="true"){
									document.getElementById("ajaxDiv2").innerHTML="Existing Nic No ";
									document.getElementById('txtNic').value="";
								}else{
									document.getElementById("ajaxDiv2").innerHTML=""; 
									
									}
									}
                                }
								var x=document.getElementById('txtRegno').value;
                               var z=document.getElementById('txtNic').value;
                               var queryString ="?nic=" + z+"&reg="+x;
                               xmlhttp.open("GET","../logic/load/student_nic_up.php"+queryString,true);
                                xmlhttp.send();	  

								
								
								} /*else{
									alert("vdgadvhasgvd");
									}*/
	                  }
	
	
		
		
		}
	
function backx()
   {
	
	var startrow=document.getElementById('startrow').value;
	var tag=document.getElementById('tag').value;
	
	
	if(tag=="home"){
		
		document.location="../admin/admin_home.php?tab=student_search&page="+startrow;
		}else {
			document.location="student_searchx.php?page="+startrow;
			}
	
	
	
	}

